//
//  JaneLoginViewController.m
//  EPA
//
//  Created by lanou3g on 16/4/26.
//  Copyright © 2016年 张静. All rights reserved.
//

#import "JaneLoginViewController.h"
#import "JaneNetWorkRequestManager.h"
#import "JaneHomePageController.h"
#import "JaneUserInfoManager.h"
#import "JaneRegistViewController.h"
#import "CK_MenuViewController.h"
@interface JaneLoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *emailTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;

@end

@implementation JaneLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
      // Do any additional setup after loading the view from its nib.
}

- (IBAction)returnBtnAction:(id)sender {
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
- (IBAction)registBtnAction:(id)sender {
    JaneRegistViewController *registVC = [[JaneRegistViewController alloc]init];
    [self presentViewController:registVC animated:YES completion:nil];
}

- (IBAction)loginBtnAction:(id)sender {
    [JaneNetWorkRequestManager requestURL:[NSURL URLWithString:LOGIN_URL] RequestMethod:CK_POST Params:@{@"email":self.emailTextField.text,@"passwd":self.passwordTextField.text} Result:^(NSData *data, NSURLResponse *response, NSError *error) {
        if (data) {
            NSMutableDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:jsonDict[@"data"][@"msg"] preferredStyle:UIAlertControllerStyleAlert];
            [alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                if ([jsonDict[@"result"]isEqual:@1]) {
                    [self dismissViewControllerAnimated:YES completion:^{
                  
                    }];
                }
            }]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self presentViewController:alertC animated:YES completion:nil];
            });
            if ([jsonDict[@"result"] isEqual:@1]) {
                [[JaneUserInfoManager shareManager]loginWithUserDict:jsonDict[@"data"]];
                               
            }
        }
    }];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
